package cn.tedu.zhwy.information.controller;

import cn.tedu.zhwy.base.response.JsonResult;
import cn.tedu.zhwy.information.pojo.dto.HouseQuery;
import cn.tedu.zhwy.information.pojo.dto.HouseSaveParam;
import cn.tedu.zhwy.information.pojo.vo.HouseVO;
import cn.tedu.zhwy.information.service.HouseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/v1/house/")
public class HouseController {
    @Autowired
    private HouseService houseService;

    @GetMapping("select")
    public JsonResult selectHouse(HouseQuery houseQuery){
        log.debug("查询房屋条件:HouseQuery={}",houseQuery);
        List<HouseVO> list = houseService.selectHouse(houseQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveHouse(HouseSaveParam houseSaveParam){
        log.debug("新增/更新房屋={}",houseSaveParam);
        houseService.saveHouse(houseSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{hid}")
    public JsonResult deleteHouse(@PathVariable Long hid){
        houseService.deleteHouse(hid);
        return JsonResult.ok();
    }
}
